<?php
declare (strict_types=1);


namespace app\admin\controller;

use app\common\controller\Admin;
use app\common\builder\Form;

class Demo extends  Admin
{
    public function demo1()
    {

        $this->addTitle('表单演示');
        $this->setHeaderTips('我是一个演示页面，我演示了所有的表单类型');
        $this->addHeaderBtn([
            'title' => '新增',
            'class' => 'layui-btn-danger',
            'icon' => 'layui-icon-add-1',
            'sort' => 10
        ])->addHeaderBtn([
            'title' => '测试2',
            'class' => ' layui-btn-normal',
            'sort' => 2,
            'href' => (string) url('demo/demo1')
        ])->addHeaderBtn([
            'title' => '测试3',
            'class' => 'layui-btn-danger',
            'sort' => 5
        ]);

        $form = new Form([
            'a' => 'aaa',
            'c' => 'nv',
        ]);


        $form->addFormItem('myicon', 'icon', [
            'label' => '图标选择',
            'attrs' => [
                'value' => 'layui-icon-cellphone'
            ]
        ]);

        $form->addFormItem('tag', 'tag', [
            'label' => '标签',
            'attrs' => [
                'value' => '测试,喜喜'
            ]
        ]);

        $form->addFormItem('xmselect', 'xmselect', [
            'label' => '更多下拉',
            'options' => [
                '16' => '16岁',
                '17' => '17岁',
                '18' => '18岁',
                '19' => '19岁',
                '20' => '20岁',
                '21' => '21岁',
                '22' => '22岁',
                '23' => '23岁'
            ],
            'attrs' => [
                'value' => '18',
                'xm-select-max'  => 3,// 最多选择3个
                //'xm-select-radio' => true, // 下拉单选
            ]
        ]);
        /*
        $form->addFormItem('tinymce', 'tinymce', [
            'label' => '富文本',
            'attrs' => [

            ]
        ]);
        */
        $form->addFormItem('array', 'array', [
            'label' => '数组',
            'attrs' => [
                'value' => '[1,2,3]'
            ]
        ]);
        $form->addFormItem('keyvalue', 'keyvalue', [
            'label' => '键值对',
            'attrs' => [
                'value' => '{"a":"aa","b":"bb","c":"{\"x\":\"xx\"}"}'
            ]
        ]);

        $form->addFormItem('image', 'image', [
            'label' => '单图',
            'attrs' => [
                //'data-url' => '' // 自定义上传接口 默认 upload/upload
                'data-data' => ['a' => '测试'], // 每次上传请求的额外数据
                'data-auto' => false, // 是否自动上传  默认true
            ]
        ]);
        $form->addFormItem('file', 'file', [
            'label' => '单文件',
        ]);
        $form->addFormItem('multiple_image', 'multiple_image', [
            'label' => '多图',
            'attrs' => [
                'data-auto' => false, // 是否自动上传  默认true
                //'value' => ['/uploads/topic/20220403/0af677ac8b344cb3d1d0928c66291cfa.jpg','/uploads/topic/20220403/1bb1484f039b3080238e0921e6f58ffc.png']
            ]
        ]);
        $form->addFormItem('multiple_file', 'multiple_file', [
            'label' => '多文件',
        ]);

        $form->addFormItem('rate', 'rate', [
            'label' => '评分',
            'attrs' => [
                // 'data-length' => 10 设定星星的数量 默认5个
                'data-half' => true,
                'data-text' => true
            ]
        ]);
        $form->addFormItem('transfer', 'transfer', [
            'label' => '穿梭框',
            'attrs' => [
                // 'data-width' => 150, //自定义宽度 默认190，
                // 'data-height' => 300,//自定义高度 默认 300
                // 'data-title' => '数据源,已选中' // 自定义2边标题
                // 'data-search' => false, // 关闭搜索 默认开启
            ],
            'options' => [
                ['value' => '1','title' => '张三'],
                ['value' => '2','title' => '李四'],
                ['value' => '3','title' => '王五'],
                ['value' => '4','title' => '赵六'],
                ['value' => '5','title' => '老师']
            ]
        ]);
        $form->addFormItem('slider', 'slider', [
            'label' => '滑块',
            'attrs' => [
                //'data-type' => 'vertical', // 滑块类型
                //'data-range' => true,
                'data-input' => true,
                'data-tips' => true
            ]
        ]);

        $form->addFormItem('color', 'color', [
            'label' => '取色',
            'attrs' => [
                //'type' => 'hidden'
                'data-format' => 'rgb', // 取值方式  rgb hex 默认hex
                'data-alpha' => true, // 是否开启透明度 默认没有
                //'data-predefine' =>  false,// 关闭预定义颜色 默认开启

            ]
        ]);
        $form->addFormItem('date', 'date', [
            'label' => '日期',
            'attrs' => [
                //'data-range' => '|', // 是否开启范围选择  true 默认是~ 也可以设定具体分隔符 |
                // 'data-format' => 'yyyy年MM月dd日' 自定义格式
                // 'data-close-preview' => true 是否关闭预览 默认开启
                // 'data-min' => '2022-03-01', 设置可选最小值
                // 'data-max' => date('Y-m-d'), 设置可选最大值
                // 'data-hide-bottom' => true  关闭底部区域
                // 'data-btns' => 'clear' 自定义底部按钮 clear、now、confirm 多个,逗号分割
                // 'data-theme' => 'molv' 主题
                //'data-calendar' => true 是否显示公历 默认不显示
                'data-mark' => json_encode(['2022-04-01' => '测试', '2022-04-02' => '牛皮'])
            ]
        ]);
        $form->addFormItem('datetime', 'datetime', [
            'label' => '日期时间',
        ]);
        $form->addFormItem('time', 'time', [
            'label' => '时间',
        ]);
        $form->addFormItem('month', 'month', [
            'label' => '年月',
        ]);
        $form->addFormItem('year', 'year', [
            'label' => '年',
        ]);

        $form->addFormItem('a', 'text', [
            'label' => '用户名',
        ])
            ->addFormItem('b', 'password', [
                'label' => '密码',
            ]);
        $form['c'] = [
            'elem' => 'radio',
            'label' => '性别',
            //'is_title' => false,
            'options' => [
                'nan' => '男',
                'nv' => '女',
                'wz' => '未知'
            ]
        ];
        $form['d'] = [
            'elem' => 'checkbox',
            'label' => '爱好',
            'options' => [
                '篮球' => '篮球',
                '足球' => '足球',
                '排球' => '排球'
            ],
            'attrs' => [
                'value' => '足球'
            ]
        ];
        $form['e'] = [
            'elem' => 'select',
            'label' => '年龄',
            'tip '=> '请选择年龄',
            'options' => [
                '16' => '16岁',
                '17' => '17岁',
                '18' => '18岁'
            ],
            'attrs' => [
                'value' => '18'
            ]
        ];
        $form['f'] = [
            'elem' => 'select',
            'label' => '风格',
            'options' => [
                '纯文风格' => [
                    '1' => '简约',
                    '2' => '标题+简介'
                ],
                '图文风格' => [
                    '3' => '图文1',
                    '4' => '图文2'
                ]
            ]
        ];

        $form->addFormItem('g', 'textarea', [
            'label' => '多行文本框',
        ]);

        $form->addFormItem('h', 'switch', [
            'label' => '开关',
            // 自定义选中和不选中的值
            /*
            'switch' => [
                'no' => 'no', // 不选中的值 默认0
                'yes' => 'ok' // 选中的值  默认1
            ],
            'attrs' => [
                'lay-text' => '对|错'
            ]
            */
        ]);
        $form->addFormItem('i2', 'text', [
            'label' => '单行带选择',
            'options' => [
                '人物' => [
                    '张三' => '张三',
                    '李四' => '李四',
                    '王五' => '王五'
                ],
                '动物' => [
                    '旺财' => '旺财',
                    '加菲猫' => '加菲猫',
                    '熊大' => '熊大'
                ]
            ]
        ]);
        $form->addFormItem('number', 'number', [
            'label' => '数字',
        ]);

        //pr($this->request->post());

        $this->assign('form', $form);
        return $this->fetch();
    }
}